package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.Car;
import com.dk.pojo.Type;
import com.dk.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("type")
public class TypeController {
    @Reference
    private TypeService typeService;
    @RequestMapping("toShow")
    public String toShow(){
        return "type/show";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<Type> getInfo(String tname){
        List<Type> list = typeService.getInfo(tname);
        return list;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "type/add";
    }
    @RequestMapping("increase")
    @ResponseBody
    public boolean increase(Type type){
        return  typeService.insert(type) > 0;
    }
    @RequestMapping("toUpdate/{cid}")
    public String toUpdate(@PathVariable("cid")Integer cid, Model model){
        Type type = typeService.selectByCid(cid);
        model.addAttribute("type",type);
        return "type/update";
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(Type type){
        return typeService.updaateInfo(type) > 0;
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer cid){
        return typeService.deleteById(cid) > 0;
    }
}
